package com.yyfax.ph.progress.search;

import android.content.res.Resources;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import butterknife.BindView;
import butterknife.ButterKnife;
import com.yyfax.ph.R;
import com.yyfax.ph.base.adapter.BaseAdapter;

import java.util.Arrays;
import java.util.List;

/**
 * 项目名称: YYLending
 * 类描述： 选择进度查询的状态
 * 创建人: zhangxian
 * 创建时间: 2016/12/27 8:37
 * 修改人: zhangxian
 * 修改时间: 2016/12/27 8:37
 * 修改备注:
 */

public class StatusAdapter extends BaseAdapter<String> {

	private List<String> mStatus = Arrays.asList("全部状态", "待处理", "审核中", "已放款", "已否决");
	private StatusItemClickListener mClickListener;
	private String mSelectedStatus = "全部状态";

	public interface StatusItemClickListener {
		void onStatusItemClick(int position, String selectStatus);//点击进行选择状态
	}

	public StatusAdapter(StatusItemClickListener listener) {
		super();
		mClickListener = listener;
	}

	@Override
	public int getCount() {
		return mStatus.size();
	}

	@Override
	public String getItem(int i) {
		return mStatus.get(i);
	}

	@Override
	public long getItemId(int i) {
		return i;
	}

	@Override
	public View getView(final int i, View convertView, ViewGroup viewGroup) {
		final ViewHolder viewHolder;
		if (convertView == null) {
			convertView = View.inflate(viewGroup.getContext(), R.layout.select_status_item_layout, null);
			viewHolder = new ViewHolder(convertView);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}
		Resources resources = viewGroup.getContext().getResources();
		if (mSelectedStatus.equals(mStatus.get(i))) {
			viewHolder.statusTv.setTextColor(resources.getColor(R.color.color_f05b47));
			viewHolder.statusSelectedIv.setVisibility(View.VISIBLE);
		} else {
			viewHolder.statusTv.setTextColor(resources.getColor(R.color.color_666666));
			viewHolder.statusSelectedIv.setVisibility(View.GONE);
		}
		viewHolder.statusTv.setText(mStatus.get(i));
		viewHolder.rl.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View view) {
				if (null != mClickListener) {
					mSelectedStatus = mStatus.get(i);
					mClickListener.onStatusItemClick(i, mStatus.get(i));
				}
			}
		});
		return convertView;
	}

	static class ViewHolder {
		@BindView(R.id.rl)
		View rl;
		@BindView(R.id.status_select_tv)
		TextView statusTv;
		@BindView(R.id.status_selected_iv)
		ImageView statusSelectedIv;

		ViewHolder(View view) {
			ButterKnife.bind(this, view);
		}
	}

	public void setSelectedStatus(String status) {
		mSelectedStatus = status;
	}

	public String getSelectedStatus() {
		return mSelectedStatus;
	}

	public List<String> getStatus() {
		return mStatus;
	}

	public void setStatus(List<String> status) {
		mStatus = status;
	}
}
